<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>vue life</title>
  <script src="../assets/js/vue.js"></script>
</head>
<body>
  <h1>vue life生命周期</h1>
  <hr>
  <div id="app">
    <p>{{ count }}</p>
    <button @click="add">add</button>
  </div>
  <button onclick="vue.$destroy()">destroy</button>
  <script>
    var vue = new Vue({
      el: '#app',
      data: {
        count: 1
      },
      methods: {
        add: function () {
          this.count++;
        },
      },
      beforeCreate: function () {
        console.log(1, '初始化之前，只调用一次');
      },
      created: function () { 
        console.log(2, '初始化之后，只调用一次');
      },
      beforeMount: function () { 
        console.log(3, '挂载之前，只调用一次');
      },
      mounted: function() {
        console.log(4, '挂载之后，只调用一次');
      },
      beforeUpdate: function () {
        console.log(5, '数据更新之前');
      },
      updated: function () { 
        console.log(6, '数据更新之后');
      },
      beforeDestroy: function() {
        console.log(7, '销毁之前，只调用一次');
      },
      destroyed: function () {
        console.log(8, '销毁之后，只调用一次');
      },
    })
  </script>
</body>
</html>